package com.learn.hibernatevalidator.chapter10;

import jakarta.validation.*;
import jakarta.validation.constraintvalidation.SupportedValidationTarget;
import jakarta.validation.constraintvalidation.ValidationTarget;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @author: liyf
 * @create: 2025-01-21 22:40
 **/

@Target({METHOD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = {LuggageCountMatchesPassengerCount.Validator.class})
@Documented
public @interface LuggageCountMatchesPassengerCount {

    String message() default "{org.hibernate.validator.referenceguide.chapter08.LuggageCountMatchesPassengerCount.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    ConstraintTarget validationAppliesTo() default ConstraintTarget.IMPLICIT;

    int piecesOfLuggagePerPassenger() default 1;

    @SupportedValidationTarget({
            ValidationTarget.PARAMETERS,
            ValidationTarget.ANNOTATED_ELEMENT
    })
    class Validator
            implements ConstraintValidator<LuggageCountMatchesPassengerCount, Object[]> {

        @Override
        public void initialize(LuggageCountMatchesPassengerCount constraintAnnotation) {
        }

        @Override
        public boolean isValid(Object[] value, ConstraintValidatorContext context) {
            return false;
        }
    }
}